//
//  SGEdgeView.m
//  SpringGraph Test
//
//  Created by Jack Herrington on 6/1/10.
//  Copyright 2010 Myself. All rights reserved.
//

#import "SGEdgeView.h"


@implementation SGEdgeView

@synthesize edgeSelected, lineColor, selectedLineColor, lineWidth;

- (void)dealloc {
	[lineColor release];
	[selectedLineColor release];
	[lineWidth release];
	[super dealloc];
}

- (void)didMoveToSuperview {
	self.clearsContextBeforeDrawing = false;
	self.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
	self.contentMode = UIViewContentModeRedraw;
	self.opaque = NO;
	self.userInteractionEnabled = NO;
	self.multipleTouchEnabled = NO;
	self.clipsToBounds = NO;
	
	self.selectedLineColor = [[UIColor blueColor] retain];
	self.lineColor = [[UIColor colorWithWhite:0.6 alpha:1] retain];
}

- (void)setLeftOrientation:(SGEdgeOrientation)orientation {
	_leftOrientation = orientation;
}

- (SGEdgeOrientation)leftOrientation {
	return _leftOrientation;
}

- (void)setRightOrientation:(SGEdgeOrientation)orientation {
	_rightOrientation = orientation;
}

- (SGEdgeOrientation)rightOrientation {
	return _rightOrientation;
}

- (void)drawRect:(CGRect)rect {
	CGContextRef context = UIGraphicsGetCurrentContext();
	
	[[UIColor colorWithWhite:0.6 alpha:1] setStroke];
	
	CGContextSetLineWidth( context, lineWidth ? [lineWidth floatValue] : 2 );
	
	self.edgeSelected ? [self.selectedLineColor setStroke] : [self.lineColor setStroke];
	
	CGContextBeginPath( context );
	CGContextMoveToPoint( context, self.bounds.origin.x,
						 self.leftOrientation == kSGEdgeOrientationTop ? self.bounds.origin.y : self.bounds.size.height );
	CGContextAddLineToPoint( context, self.bounds.size.width,
						 self.rightOrientation == kSGEdgeOrientationTop ? self.bounds.origin.y : self.bounds.size.height );
	CGContextStrokePath( context );
}

@end
